import mz.matafe.bolao.User

security {
    
    // see DefaultSecurityConfig.groovy for all settable/overridable properties
    active = true
    loginUserDomainClass = "mz.matafe.bolao.User"
    authorityDomainClass = "mz.matafe.bolao.Role"
    useRequestMapDomainClass = false
    useControllerAnnotations = true
    password = 'password'
    enabled = 'active'
    relationalAuthorities = 'roles'
    authorityField = 'code'
    defaultTargetUrl = '/bet/list'
    controllerAnnotationsRejectIfNoRule = true
    controllerAnnotationStaticRules = [
      '/**/js/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
      '/**/css/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
      '/**/images/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
      '/*': ['IS_AUTHENTICATED_ANONYMOUSLY']
    ]

    onAuthenticationSuccessEvent = { e, appCtx ->
        User.withTransaction { status ->
            def user = e.authentication.principal.domainClass
            user.attach()
            user.lastLoginDate = user.loginDate == null ? new Date() : user.loginDate
            user.loginDate=new Date()
            user.save(flush:true)
        }
    }
}
